using System;
using System.Linq.Expressions;

namespace DuplexTransformers
{
    public class LeftExpression<TLeft, TRight, TLeftProp>
    {
        protected readonly Transformer<TLeft, TRight> Transformer;
        protected readonly Expression<Func<TLeft, TLeftProp>> WrappedExpr;

        public LeftExpression(Transformer<TLeft, TRight> transformer, Expression<Func<TLeft, TLeftProp>> expr)
        {
            Transformer = transformer;
            WrappedExpr = expr;
        }

        public void MapsTo(Expression<Func<TRight, TLeftProp>> expr)
        {
            TransformedBy(new PassthruTransformer<TLeftProp>()).MapsTo(expr);
        }

        public PropertyRelationshipTransformerExpression<TLeft, TRight, TLeftProp, TRightProp> TransformedBy<TRightProp>(ITransformer<TLeftProp, TRightProp> transformer)
        {
            return new PropertyRelationshipTransformerExpression<TLeft, TRight, TLeftProp, TRightProp>(x=>Transformer.AddRelationship(x), WrappedExpr, transformer);
        }

        public PropertyRelationshipTransformerExpression<TLeft, TRight, TLeftProp, TRightProp> TransformedBy<TRightProp>(Func<TLeftProp, TRightProp> leftFunc, Func<TRightProp, TLeftProp> rightFunc)
        {
            return TransformedBy(new LiteTransformer<TLeftProp, TRightProp>(leftFunc, rightFunc));
        }
    }
}